package com.itheima.edu.info.manger.service;

import com.itheima.edu.info.manger.dao.TeacherDao;
import com.itheima.edu.info.manger.domain.Teacher;

public class TeacherService {
    private TeacherDao teacherDao=new TeacherDao();

    public boolean addTeacher(Teacher teacher){
        //1.TeacherDao对象调用addTeacher方法，传入student参数将返回值返回。
        return teacherDao.addTeacher(teacher);
    }
    /**
     * 判断教师工号是否存在
     * 存在 true  不存在 false
     */
    public boolean isExists(String id){
        Teacher[] teachers=teacherDao.findAll();
        for (int i = 0; i < teachers.length; i++) {
            if (teachers[i] != null && teachers[i].getId().equals(id)) {
                return true;
            }
        }
        return false;
    }
    /**
     * 查询所有学生的方法
     * 学生数组
     */
    public Teacher[] findAll(){
        //通过TeacherDao查询到所有学生数组后并返回
        Teacher[] teachers=teacherDao.findAll();
        boolean flag=false;//默认为空
        for (int i = 0; i < teachers.length; i++) {
            if(teachers[i]!=null){
                flag=true;
                break;
            }
        }
        if(flag){
            return teachers;

        }else{
            return null;
        }

    }

}
